package com.atguigu.utils;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

public class KeyWordUtil {

    public static List<String> getKeyWord(String keyWord) throws IOException {

        // 创建一个集合用于存放分词结果
        ArrayList<String> list = new ArrayList<>();

        // 获取IK分词器对象
        IKSegmenter ikSegmenter = new IKSegmenter(new StringReader(keyWord), false);

        Lexeme next = ikSegmenter.next();

        while (next != null){
            String word = next.getLexemeText();
            list.add(word);

            next = ikSegmenter.next();
        }

        return list;
    }


    public static void main(String[] args) throws IOException {

        String keywords = "上海大数据210927 Flink实时数仓项目DWS层";
        System.out.println(getKeyWord(keywords));

    }

}
